package com.jackrain.nea.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.jackrain.nea.utility.ServiceUtil;
import com.jackrain.nea.core.utility.JSONUtil;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(value = "MetadataController", description = "元数据管理 blqw")
@RestController
public class MetadataController {

    private static Class getCommandClass() {
        String prefix = "com.jackrain.nea.core.api.";
        String suffix = "Cmd";
        try {
            return Class.forName(prefix + Thread.currentThread().getStackTrace()[2].getMethodName() + suffix);
        } catch (ClassNotFoundException e) {
            return null;
        }
    }

    @ApiOperation(value = "删除 [10004 字段选项值 ] 的数据 ")
    @RequestMapping(path = "/p/cs/AdLimitValueGroupDel", method = RequestMethod.DELETE)
    public JSONObject AdLimitValueGroupDel(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }

    @ApiOperation(value = "新增 [10007 关联表 ] 的数据 ")
    @RequestMapping(path = "/p/cs/AdRefbyTableAdd", method = RequestMethod.POST)
    public JSONObject AdRefbyTableAdd(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(),"ad",  request, JSONUtil.Standardization(param));
    }

    @ApiOperation(value = "删除 [10003 字段 ] 的数据")
    @RequestMapping(path = "/p/cs/AdColumnDel", method = RequestMethod.DELETE)
    public JSONObject AdColumnDel(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }

    @ApiOperation(value = "更新 [10010 表 ] 的数据 ")
    @RequestMapping(path = "/p/cs/AdTableSave", method = RequestMethod.PATCH)
    public JSONObject AdTableSave(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }


    @ApiOperation(value = "删除 [10010 表 ] 的数据")
    @RequestMapping(path = "/p/cs/AdTableDel", method = RequestMethod.DELETE)
    public JSONObject AdTableDel(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }

    @ApiOperation(value = "更新 [10101 表SQL ] 的数据")
    @RequestMapping(path = "/p/cs/AdTableSqlSave", method = RequestMethod.PATCH)
    public JSONObject AdTableSqlSave(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }

    @ApiOperation(value = "新增或更新 [10003 字段 ] 的数据")
    @RequestMapping(path = "/p/cs/AdColumnSave", method = {RequestMethod.POST, RequestMethod.PATCH})
    public JSONObject AdColumnSave(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }

    @ApiOperation(value = "新增 [10010 表 ] 的数据")
    @RequestMapping(path = "/p/cs/AdTableAdd", method = RequestMethod.POST)
    public JSONObject AdTableAdd(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }

    @ApiOperation(value = "新增或修改 字段选项组")
    @RequestMapping(path = "/p/cs/AdLimitValueGroupSave", method = RequestMethod.POST)
    public JSONObject AdLimitValueGroupSave(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }

    @ApiOperation(value = "删除 表类别")
    @RequestMapping(path = "/p/cs/AdTableCategoryDel", method = RequestMethod.POST)
    public JSONObject AdTableCategoryDel(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }

    @ApiOperation(value = "克隆表")
    @RequestMapping(path = "/p/cs/CloneTable", method = RequestMethod.POST)
    public JSONObject CloneTable(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }


    @ApiOperation(value = "新增或修改 子系统")
    @RequestMapping(path = "/p/cs/AdSubsystemSave", method = RequestMethod.POST)
    public JSONObject AdSubsystemSave(HttpServletRequest request, @RequestParam(value = "param") String param) throws Exception {
        return ServiceUtil.testInvoke(getCommandClass(), "ad", request, JSONUtil.Standardization(param));
    }
}
